import Vue from 'vue'
import Vuex from 'vuex'
import localStorage from '../utils/localStorage'
import createPersistedState from 'vuex-persistedstate'

import user from './modules/user'
import menu from './modules/menu'
Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    user,
    menu
  },
  // 插件
  plugins: [createPersistedState({
    key: require('../../package.json').name + 'vuex',
    paths: ['user', 'menu'], // 只缓存service里的state
    getState: (key) => localStorage.get(key),
    setState: (key, state) => localStorage.set(key, state)
  })]
})
